package cn.zcscloud.mall.service.impl;

import cn.zcscloud.mall.mbg.mapper.SmsFlashPromotionMapper;
import cn.zcscloud.mall.mbg.mapper.SmsFlashPromotionProductRelationMapper;
import cn.zcscloud.mall.mbg.model.SmsFlashPromotion;
import cn.zcscloud.mall.mbg.model.SmsFlashPromotionProductRelation;
import cn.zcscloud.mall.service.PmsProductService;
import cn.zcscloud.mall.service.SmsFlashPromotionProductRelationService;
import cn.zcscloud.mall.service.SmsFlashPromotionService;
import cn.zcscloud.mall.vo.SmsFlashPromotionProductVo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class SmsFlashPromotionProductRelationServiceImpl extends ServiceImpl<SmsFlashPromotionProductRelationMapper, SmsFlashPromotionProductRelation> implements SmsFlashPromotionProductRelationService {

    @Autowired
    private SmsFlashPromotionProductRelationMapper smsFlashPromotionProductRelationMapper;
    @Autowired
    private PmsProductService productService;

    public IPage<SmsFlashPromotionProductVo> getList(Page<SmsFlashPromotionProductVo> page, Long flashPromotionId, Long flashPromotionSessionId){
        IPage<SmsFlashPromotionProductVo> listPage = smsFlashPromotionProductRelationMapper.getListPage(page, flashPromotionId, flashPromotionSessionId);
        for (SmsFlashPromotionProductVo record : listPage.getRecords()) {
            Long productId = record.getProductId();
            record.setProduct(productService.getById(productId));
        }
        return listPage;
    }
}
